package com.es.order.controller;


import com.es.order.entity.OrderDO;
import com.es.order.service.OrderRabbitService;
import com.es.order.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import com.es.core.controller.BaseController;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author everysucceed
 * @since 2021-12-09
 */
@Slf4j
@RestController
@RequestMapping("/order")
public class OrderController extends BaseController {

    @Autowired
    private OrderService service;
    @Autowired
    private OrderRabbitService rabbitService;

    @GetMapping("/submit")
    public String submit(String title){
        OrderDO orderDO = new OrderDO();
        orderDO.setOrderTitle(title);
        orderDO.setOrderStatus(2);
        service.save(orderDO);
        log.info("订单号是:{}", orderDO.getOrderId());
        rabbitService.sendOrderId(orderDO.getOrderId());
        return "下单成功";
    }

    @GetMapping("/list")
    public List<OrderDO> list(){
        List<OrderDO> list = service.list();
        return list;
    }



}
